#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1005;
int f[maxn],n;

struct man{
	int iq,eq;
}a[maxn];

bool cmp(man a,man b){
	if(a.iq == b.iq) return a.eq<=b.eq;
	return a.iq<=b.iq;
}

int main(){
	cin>>n;
	int x,y;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		a[i].iq = x;
		a[i].eq = y;
	}
	sort(a+1,a+n+1,cmp);
	//最长不下降子序列 
	f[1]=1;
	for(int i=2;i<=n;i++){
		for(int j=1;j<i;j++){
			if(a[j].eq<a[i].eq)	f[i]=max(f[i],f[j]);
		}
		f[i]++;
	}
	
	int ans = f[1];
    for(int i=1;i<=n;i++){
        ans = max(ans,f[i]);
    }
    cout<<ans<<endl;
}
